package com.qms.repast.ui.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.orhanobut.logger.Logger;
import com.qms.repast.commons.Constants;
import com.qms.repast.entity.reqbean.SearchBean;
import com.qms.repast.entity.resbean.ShopInfo;
import com.qms.repast.module.UserModule;
import com.qms.repast.ui.base.BasePresenter;
import com.qms.repast.ui.view.IRecycleView;

import io.reactivex.observers.DisposableObserver;

/**
 * @author 泅渡者
 * @date 2018/9/20 0020
 * @describe:
 */
public class RecycleViewPresenter extends BasePresenter<IRecycleView> {
	protected UserModule userModule;

	public RecycleViewPresenter (Activity mContext, IRecycleView mView) {
		super(mContext, mView);
		userModule = new UserModule(mContext);
	}

	public void getShopList (SearchBean searchBean) {
		userModule.reqShopList(searchBean, new DisposableObserver<ShopInfo>() {
			@Override
			public void onError (Throwable throwable) {
				Logger.e(throwable.getMessage());
			}

			@Override
			public void onComplete () {
				Logger.d("Request is End");
			}

			@Override
			public void onNext (ShopInfo shopInfo) {
				Logger.json(new Gson().toJson(shopInfo));
				if (Constants.SUCCESS == shopInfo.getCode()) {
					mView.initShopList(shopInfo.getBody().getRows());
				}
			}
		});
	}
}
